package com.lamatek.tags.google;

import java.io.Serializable;

import javax.servlet.jsp.tagext.BodyTagSupport;
import javax.servlet.jsp.tagext.Tag;

import com.lamatek.tags.google.beans.EscapeChars;

/**
 * GoogleMapBodyTag
 * 
 * This tag corresponds to the &lt;googlemaps:message> tag. Developers should
 * not extend this class or override it's methods.
 * 
 * @author Tom Cole
 * @version 0.40
 */
public class GoogleMapMessageTag extends BodyTagSupport implements Serializable {

    String content = "";
    String style = null;
    /**
     * Overrides doStartTag() in BodyTagSupport.
     */
    public int doStartTag() {
        return EVAL_BODY_BUFFERED;
    }
    /**
     * Overrides doEndTag() in BodyTagSupport. Developers should not
     * override this method.
     */
    public int doEndTag() {
        content = EscapeChars.escape(getBodyContent().getString().trim());
        Tag tag = this;
        while (tag.getParent() != null) {
            if (tag.getParent() instanceof GoogleMapTag) {
                ((GoogleMapTag) tag.getParent()).setMessage(this);
                return EVAL_PAGE;
            }
            tag = tag.getParent();
        }
        return EVAL_PAGE;
    }
    /**
     * Returns the message body text. If html is set to true, this will be escaped.
     * 
     * @return Message body text.
     */
    public String getMessage() {
        return content;
    }
    /**
     * Sets the message body text. If html is set to true, this will be escaped.
     * 
     * @param message Message body text.
     */
    public void setMessage(String message) {
        this.content = message.trim();
    }
    /**
     * Sets the css_style to use for the message.
     * 
     * @param style The css_style to apply to the message.
     */
    public void setStyle(String style) {
        this.style = style;
    }
    /**
     * Returns the css_style for this message.
     * 
     * @return A css style string.
     */
    public String getStyle() {
        return style;
    }
}
